package com.hc.window.settingView;

import javax.jws.Oneway;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import com.hc.util.CommonData;
import com.hc.util.SystemConfigUtil;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class Setting_baseStation_FH extends JPanel implements ActionListener{
	private JTextField textField_b1;
	private JTextField textField_b2;
	private JTextField textField_b4;
	private JTextField textField_b3;
	private JCheckBox isUseBFH1;
	private JCheckBox isUseBFH2;
	private JCheckBox isUseBFH3;
	private JCheckBox isUseBFH4;
	public Setting_baseStation_FH() {
		setLayout(null);
		
		JLabel lblNewLabel = new JLabel("\u57FA\u7AD91\uFF1A");
		lblNewLabel.setBounds(95, 23, 48, 26);
		add(lblNewLabel);
		
		textField_b1 = new JTextField();
		textField_b1.setBounds(153, 23, 161, 26);
		add(textField_b1);
		textField_b1.setColumns(10);
		
		JLabel label_1 = new JLabel("\u57FA\u7AD92\uFF1A");
		label_1.setBounds(95, 59, 48, 26);
		add(label_1);
		
		textField_b2 = new JTextField();
		textField_b2.setColumns(10);
		textField_b2.setBounds(153, 59, 161, 26);
		add(textField_b2);
		
		textField_b4 = new JTextField();
		
		textField_b4.setColumns(10);
		textField_b4.setBounds(153, 131, 161, 26);
		add(textField_b4);
		
		JLabel label = new JLabel("\u57FA\u7AD93\uFF1A");
		label.setBounds(95, 95, 48, 26);
		add(label);
		
		textField_b3 = new JTextField();

		textField_b3.setColumns(10);
		textField_b3.setBounds(153, 95, 161, 26);
		add(textField_b3);
		
		JLabel label_2 = new JLabel("\u57FA\u7AD94\uFF1A");
		label_2.setBounds(95, 131, 48, 26);
		add(label_2);
		
		isUseBFH1 = new JCheckBox("\u4F7F\u7528");
		isUseBFH1.setBounds(338, 25, 85, 23);
		add(isUseBFH1);
		
		isUseBFH2 = new JCheckBox("\u4F7F\u7528");
		isUseBFH2.setBounds(338, 61, 85, 23);
		add(isUseBFH2);
		
		isUseBFH3 = new JCheckBox("\u4F7F\u7528");
		isUseBFH3.setBounds(338, 97, 85, 23);
		add(isUseBFH3);
		
		isUseBFH4 = new JCheckBox("\u4F7F\u7528");
		isUseBFH4.setBounds(338, 132, 85, 23);
		add(isUseBFH4);
		isUseBFH1.addActionListener(this);
		isUseBFH2.addActionListener(this);
		isUseBFH3.addActionListener(this);
		isUseBFH4.addActionListener(this);
		
		JButton button = new JButton("\u786E\u5B9A");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				CommonData.baseStation_FH_1 = Integer.parseInt(textField_b1.getText());
				CommonData.baseStation_FH_2 = Integer.parseInt(textField_b2.getText());
				CommonData.baseStation_FH_3 = Integer.parseInt(textField_b3.getText());
				CommonData.baseStation_FH_4 = Integer.parseInt(textField_b4.getText());
				
				
				SystemConfigUtil.writeConfig();
			}
		});
		button.setBounds(464, 131, 95, 25);
		add(button);
		
		iniData();
	}
	
	
	
	private void iniData() {
		textField_b1.setText(CommonData.baseStation_FH_1+"");
		textField_b2.setText(CommonData.baseStation_FH_2+"");
		textField_b3.setText(CommonData.baseStation_FH_3+"");
		textField_b4.setText(CommonData.baseStation_FH_4+"");
		
		if(CommonData.isUseBaseStation_FH_1){
			
			isUseBFH1.setSelected(true);
		}else{
			
			isUseBFH1.setSelected(false);
			textField_b1.setEnabled(false);
		}
		if(CommonData.isUseBaseStation_FH_2){
				
			isUseBFH2.setSelected(true);
		}else{
			
			isUseBFH2.setSelected(false);
			textField_b2.setEnabled(false);
		}
		if(CommonData.isUseBaseStation_FH_3){
			
			isUseBFH3.setSelected(true);
		}else{
			
			isUseBFH3.setSelected(false);
			textField_b3.setEnabled(false);
		}
		if(CommonData.isUseBaseStation_FH_4){
			
			isUseBFH4.setSelected(true);
		}else{
			isUseBFH4.setSelected(false);
			textField_b4.setEnabled(false);
		}
	
	}










	@Override
	public void actionPerformed(ActionEvent e) {

		
		if(e.getSource().equals(isUseBFH1)){
			
			if(isUseBFH1.isSelected()){
				
				isUseBFH1.setSelected(true);
				CommonData.isUseBaseStation_FH_1 = true;
				
				textField_b1.setEnabled(true);

			}else{
				isUseBFH1.setSelected(false);
				CommonData.isUseBaseStation_FH_1 = false;
				textField_b1.setEnabled(false);
			}
		
			
		}else if(e.getSource().equals(isUseBFH2)){
			
			if(isUseBFH2.isSelected()){
				
				isUseBFH2.setSelected(true);
				CommonData.isUseBaseStation_FH_2 = true;
				textField_b2.setEnabled(true);
			}else{
				isUseBFH2.setSelected(false);
				CommonData.isUseBaseStation_FH_2 = false;
				textField_b2.setEnabled(false);
			}
		}else if(e.getSource().equals(isUseBFH3)){
			if(isUseBFH3.isSelected()){
				textField_b3.setEnabled(true);
				isUseBFH3.setSelected(true);
				CommonData.isUseBaseStation_FH_3 = true;
			}else{
				isUseBFH3.setSelected(false);
				CommonData.isUseBaseStation_FH_3 = false;
				textField_b3.setEnabled(false);
			}
			
		}else if(e.getSource().equals(isUseBFH4)){
			
			if(isUseBFH4.isSelected()){
				textField_b4.setEnabled(true);
				isUseBFH4.setSelected(true);
				CommonData.isUseBaseStation_FH_4 = true;
			}else{
				isUseBFH4.setSelected(false);
				CommonData.isUseBaseStation_FH_4 = false;
				textField_b4.setEnabled(false);
			}
		}
		
	
		SystemConfigUtil.writeConfig();
	}
}
